/**
 * @author zhaozeyang
 * @date 2018/11/1 16:33
 * @description
 */
public class 五十三 {

    public static void main(String[] args) {
     System.out.println(maxSubArray(new int[]{-2,1,-3,4,-1,2,1,-5,4}));
    }

    public static   int maxSubArray(int[] nums) {
        int maxScore = Integer.MIN_VALUE;
        int now = 0;
        for (int i = 0; i < nums.length; i++) {
            if (nums[i] > maxScore) {
                maxScore = nums[i];
            }
            if (now + nums[i] > 0) {
                now = now + nums[i];
                if (now > maxScore) {
                    maxScore = now;
                }
            } else {
                now = 0;
            }
        }
        return maxScore;
    }
}
